Improve VirtualThread context tracking instrumentation#11009
Improve VirtualThread context tracking instrumentation#11009gh-worker-dd-mergequeue-cf854d[bot] merged 4 commits intomasterfrom
Conversation
…en VirtualThread and Runnable
Replaces the `ConcurrentState` approach (which activated/closed individual scopes) with `VirtualThreadState` that swaps the entire scope stack via `Context#swap()`. This correctly handles child spans created during virtual thread execution and avoids out-of-order scope closing. The new approach mirrors the ZIO FiberContext and Kotlin coroutines instrumentation patterns.
ea327b5 to
d0e39d9
Compare
Replaces the `ConcurrentState` approach (which activated/closed individual scopes) with `VirtualThreadState` that swaps the entire scope stack via `Context#swap()`. This correctly handles child spans created during virtual thread execution and avoids out-of-order scope closing. The new approach mirrors the ZIO FiberContext and Kotlin coroutines instrumentation patterns.
2788193 to
45d06be
Compare
BenchmarksStartupParameters
See matching parameters
SummaryFound 0 performance improvements and 0 performance regressions! Performance is the same for 61 metrics, 10 unstable metrics. Startup time reports for insecure-bankgantt
title insecure-bank - global startup overhead: candidate=1.62.0-SNAPSHOT~3cba9218f8, baseline=1.62.0-SNAPSHOT~9f89a0b26cc
dateFormat X
axisFormat %s
section tracing
Agent [baseline] (1.057 s) : 0, 1056521
Total [baseline] (8.873 s) : 0, 8873240
Agent [candidate] (1.058 s) : 0, 1058469
Total [candidate] (8.827 s) : 0, 8827099
section iast
Agent [baseline] (1.223 s) : 0, 1222832
Total [baseline] (9.529 s) : 0, 9528671
Agent [candidate] (1.222 s) : 0, 1221771
Total [candidate] (9.58 s) : 0, 9579991
gantt
title insecure-bank - break down per module: candidate=1.62.0-SNAPSHOT~3cba9218f8, baseline=1.62.0-SNAPSHOT~9f89a0b26cc
dateFormat X
axisFormat %s
section tracing
crashtracking [baseline] (1.246 ms) : 0, 1246
crashtracking [candidate] (1.236 ms) : 0, 1236
BytebuddyAgent [baseline] (631.519 ms) : 0, 631519
BytebuddyAgent [candidate] (633.293 ms) : 0, 633293
AgentMeter [baseline] (29.431 ms) : 0, 29431
AgentMeter [candidate] (29.462 ms) : 0, 29462
GlobalTracer [baseline] (248.441 ms) : 0, 248441
GlobalTracer [candidate] (249.364 ms) : 0, 249364
AppSec [baseline] (32.044 ms) : 0, 32044
AppSec [candidate] (32.034 ms) : 0, 32034
Debugger [baseline] (59.145 ms) : 0, 59145
Debugger [candidate] (59.221 ms) : 0, 59221
Remote Config [baseline] (601.385 µs) : 0, 601
Remote Config [candidate] (599.559 µs) : 0, 600
Telemetry [baseline] (8.107 ms) : 0, 8107
Telemetry [candidate] (8.041 ms) : 0, 8041
Flare Poller [baseline] (9.761 ms) : 0, 9761
Flare Poller [candidate] (8.907 ms) : 0, 8907
section iast
crashtracking [baseline] (1.236 ms) : 0, 1236
crashtracking [candidate] (1.245 ms) : 0, 1245
BytebuddyAgent [baseline] (799.968 ms) : 0, 799968
BytebuddyAgent [candidate] (799.815 ms) : 0, 799815
AgentMeter [baseline] (11.375 ms) : 0, 11375
AgentMeter [candidate] (11.377 ms) : 0, 11377
GlobalTracer [baseline] (239.256 ms) : 0, 239256
GlobalTracer [candidate] (238.983 ms) : 0, 238983
IAST [baseline] (25.79 ms) : 0, 25790
IAST [candidate] (25.758 ms) : 0, 25758
AppSec [baseline] (32.629 ms) : 0, 32629
AppSec [candidate] (31.677 ms) : 0, 31677
Debugger [baseline] (60.437 ms) : 0, 60437
Debugger [candidate] (62.741 ms) : 0, 62741
Remote Config [baseline] (532.757 µs) : 0, 533
Remote Config [candidate] (540.861 µs) : 0, 541
Telemetry [baseline] (11.99 ms) : 0, 11990
Telemetry [candidate] (10.021 ms) : 0, 10021
Flare Poller [baseline] (3.421 ms) : 0, 3421
Flare Poller [candidate] (3.435 ms) : 0, 3435
Startup time reports for petclinicgantt
title petclinic - global startup overhead: candidate=1.62.0-SNAPSHOT~3cba9218f8, baseline=1.62.0-SNAPSHOT~9f89a0b26cc
dateFormat X
axisFormat %s
section tracing
Agent [baseline] (1.059 s) : 0, 1058575
Total [baseline] (11.149 s) : 0, 11148574
Agent [candidate] (1.067 s) : 0, 1066516
Total [candidate] (11.087 s) : 0, 11086530
section appsec
Agent [baseline] (1.257 s) : 0, 1256581
Total [baseline] (11.172 s) : 0, 11172243
Agent [candidate] (1.25 s) : 0, 1250318
Total [candidate] (11.181 s) : 0, 11180901
section iast
Agent [baseline] (1.225 s) : 0, 1224904
Total [baseline] (11.206 s) : 0, 11205822
Agent [candidate] (1.223 s) : 0, 1222807
Total [candidate] (11.253 s) : 0, 11252810
section profiling
Agent [baseline] (1.183 s) : 0, 1183214
Total [baseline] (11.067 s) : 0, 11066552
Agent [candidate] (1.184 s) : 0, 1183975
Total [candidate] (11.025 s) : 0, 11025470
gantt
title petclinic - break down per module: candidate=1.62.0-SNAPSHOT~3cba9218f8, baseline=1.62.0-SNAPSHOT~9f89a0b26cc
dateFormat X
axisFormat %s
section tracing
crashtracking [baseline] (1.258 ms) : 0, 1258
crashtracking [candidate] (1.25 ms) : 0, 1250
BytebuddyAgent [baseline] (633.406 ms) : 0, 633406
BytebuddyAgent [candidate] (636.82 ms) : 0, 636820
AgentMeter [baseline] (29.405 ms) : 0, 29405
AgentMeter [candidate] (29.737 ms) : 0, 29737
GlobalTracer [baseline] (249.171 ms) : 0, 249171
GlobalTracer [candidate] (250.458 ms) : 0, 250458
AppSec [baseline] (32.084 ms) : 0, 32084
AppSec [candidate] (32.165 ms) : 0, 32165
Debugger [baseline] (60.136 ms) : 0, 60136
Debugger [candidate] (60.329 ms) : 0, 60329
Remote Config [baseline] (601.056 µs) : 0, 601
Remote Config [candidate] (598.642 µs) : 0, 599
Telemetry [baseline] (8.059 ms) : 0, 8059
Telemetry [candidate] (8.162 ms) : 0, 8162
Flare Poller [baseline] (8.264 ms) : 0, 8264
Flare Poller [candidate] (10.673 ms) : 0, 10673
section appsec
crashtracking [baseline] (1.25 ms) : 0, 1250
crashtracking [candidate] (1.219 ms) : 0, 1219
BytebuddyAgent [baseline] (666.682 ms) : 0, 666682
BytebuddyAgent [candidate] (661.94 ms) : 0, 661940
AgentMeter [baseline] (12.116 ms) : 0, 12116
AgentMeter [candidate] (12.2 ms) : 0, 12200
GlobalTracer [baseline] (250.802 ms) : 0, 250802
GlobalTracer [candidate] (251.168 ms) : 0, 251168
IAST [baseline] (24.758 ms) : 0, 24758
IAST [candidate] (24.409 ms) : 0, 24409
AppSec [baseline] (185.428 ms) : 0, 185428
AppSec [candidate] (183.945 ms) : 0, 183945
Debugger [baseline] (66.162 ms) : 0, 66162
Debugger [candidate] (66.292 ms) : 0, 66292
Remote Config [baseline] (604.439 µs) : 0, 604
Remote Config [candidate] (604.942 µs) : 0, 605
Telemetry [baseline] (8.587 ms) : 0, 8587
Telemetry [candidate] (8.503 ms) : 0, 8503
Flare Poller [baseline] (3.518 ms) : 0, 3518
Flare Poller [candidate] (3.603 ms) : 0, 3603
section iast
crashtracking [baseline] (1.23 ms) : 0, 1230
crashtracking [candidate] (1.232 ms) : 0, 1232
BytebuddyAgent [baseline] (800.435 ms) : 0, 800435
BytebuddyAgent [candidate] (799.057 ms) : 0, 799057
AgentMeter [baseline] (11.387 ms) : 0, 11387
AgentMeter [candidate] (11.392 ms) : 0, 11392
GlobalTracer [baseline] (239.449 ms) : 0, 239449
GlobalTracer [candidate] (239.183 ms) : 0, 239183
IAST [baseline] (25.847 ms) : 0, 25847
IAST [candidate] (26.558 ms) : 0, 26558
AppSec [baseline] (31.216 ms) : 0, 31216
AppSec [candidate] (31.893 ms) : 0, 31893
Debugger [baseline] (62.644 ms) : 0, 62644
Debugger [candidate] (63.13 ms) : 0, 63130
Remote Config [baseline] (547.612 µs) : 0, 548
Remote Config [candidate] (555.675 µs) : 0, 556
Telemetry [baseline] (12.24 ms) : 0, 12240
Telemetry [candidate] (9.927 ms) : 0, 9927
Flare Poller [baseline] (3.517 ms) : 0, 3517
Flare Poller [candidate] (3.7 ms) : 0, 3700
section profiling
crashtracking [baseline] (1.188 ms) : 0, 1188
crashtracking [candidate] (1.176 ms) : 0, 1176
BytebuddyAgent [baseline] (690.565 ms) : 0, 690565
BytebuddyAgent [candidate] (690.651 ms) : 0, 690651
AgentMeter [baseline] (9.101 ms) : 0, 9101
AgentMeter [candidate] (9.173 ms) : 0, 9173
GlobalTracer [baseline] (206.98 ms) : 0, 206980
GlobalTracer [candidate] (207.445 ms) : 0, 207445
AppSec [baseline] (32.484 ms) : 0, 32484
AppSec [candidate] (32.542 ms) : 0, 32542
Debugger [baseline] (65.443 ms) : 0, 65443
Debugger [candidate] (65.703 ms) : 0, 65703
Remote Config [baseline] (562.399 µs) : 0, 562
Remote Config [candidate] (567.52 µs) : 0, 568
Telemetry [baseline] (7.876 ms) : 0, 7876
Telemetry [candidate] (7.84 ms) : 0, 7840
Flare Poller [baseline] (3.563 ms) : 0, 3563
Flare Poller [candidate] (3.572 ms) : 0, 3572
ProfilingAgent [baseline] (94.103 ms) : 0, 94103
ProfilingAgent [candidate] (93.996 ms) : 0, 93996
Profiling [baseline] (94.665 ms) : 0, 94665
Profiling [candidate] (94.579 ms) : 0, 94579
LoadParameters
See matching parameters
SummaryFound 3 performance improvements and 0 performance regressions! Performance is the same for 17 metrics, 16 unstable metrics.
Request duration reports for petclinicgantt
title petclinic - request duration [CI 0.99] : candidate=1.62.0-SNAPSHOT~3cba9218f8, baseline=1.62.0-SNAPSHOT~9f89a0b26cc
dateFormat X
axisFormat %s
section baseline
no_agent (18.412 ms) : 18223, 18600
. : milestone, 18412,
appsec (18.759 ms) : 18572, 18947
. : milestone, 18759,
code_origins (18.231 ms) : 18049, 18413
. : milestone, 18231,
iast (18.952 ms) : 18767, 19136
. : milestone, 18952,
profiling (19.455 ms) : 19259, 19650
. : milestone, 19455,
tracing (18.616 ms) : 18429, 18803
. : milestone, 18616,
section candidate
no_agent (19.108 ms) : 18916, 19299
. : milestone, 19108,
appsec (18.715 ms) : 18523, 18907
. : milestone, 18715,
code_origins (17.752 ms) : 17580, 17925
. : milestone, 17752,
iast (19.013 ms) : 18827, 19200
. : milestone, 19013,
profiling (18.364 ms) : 18181, 18546
. : milestone, 18364,
tracing (17.657 ms) : 17481, 17833
. : milestone, 17657,
Request duration reports for insecure-bankgantt
title insecure-bank - request duration [CI 0.99] : candidate=1.62.0-SNAPSHOT~3cba9218f8, baseline=1.62.0-SNAPSHOT~9f89a0b26cc
dateFormat X
axisFormat %s
section baseline
no_agent (1.23 ms) : 1218, 1242
. : milestone, 1230,
iast (3.284 ms) : 3234, 3334
. : milestone, 3284,
iast_FULL (6.092 ms) : 6030, 6154
. : milestone, 6092,
iast_GLOBAL (3.701 ms) : 3640, 3761
. : milestone, 3701,
profiling (2.02 ms) : 2002, 2038
. : milestone, 2020,
tracing (1.84 ms) : 1825, 1855
. : milestone, 1840,
section candidate
no_agent (1.223 ms) : 1212, 1235
. : milestone, 1223,
iast (3.228 ms) : 3187, 3269
. : milestone, 3228,
iast_FULL (5.985 ms) : 5924, 6046
. : milestone, 5985,
iast_GLOBAL (3.659 ms) : 3603, 3715
. : milestone, 3659,
profiling (2.141 ms) : 2123, 2159
. : milestone, 2141,
tracing (1.889 ms) : 1872, 1906
. : milestone, 1889,
DacapoParameters
See matching parameters
SummaryFound 1 performance improvements and 0 performance regressions! Performance is the same for 11 metrics, 0 unstable metrics.
Execution time for tomcatgantt
title tomcat - execution time [CI 0.99] : candidate=1.62.0-SNAPSHOT~3cba9218f8, baseline=1.62.0-SNAPSHOT~9f89a0b26cc
dateFormat X
axisFormat %s
section baseline
no_agent (1.498 ms) : 1486, 1510
. : milestone, 1498,
appsec (3.854 ms) : 3632, 4077
. : milestone, 3854,
iast (2.279 ms) : 2210, 2348
. : milestone, 2279,
iast_GLOBAL (2.328 ms) : 2258, 2397
. : milestone, 2328,
profiling (2.101 ms) : 2046, 2156
. : milestone, 2101,
tracing (2.099 ms) : 2045, 2152
. : milestone, 2099,
section candidate
no_agent (1.499 ms) : 1487, 1511
. : milestone, 1499,
appsec (2.545 ms) : 2491, 2600
. : milestone, 2545,
iast (2.288 ms) : 2219, 2358
. : milestone, 2288,
iast_GLOBAL (2.328 ms) : 2258, 2397
. : milestone, 2328,
profiling (2.113 ms) : 2058, 2168
. : milestone, 2113,
tracing (2.093 ms) : 2040, 2146
. : milestone, 2093,
Execution time for biojavagantt
title biojava - execution time [CI 0.99] : candidate=1.62.0-SNAPSHOT~3cba9218f8, baseline=1.62.0-SNAPSHOT~9f89a0b26cc
dateFormat X
axisFormat %s
section baseline
no_agent (14.928 s) : 14928000, 14928000
. : milestone, 14928000,
appsec (14.845 s) : 14845000, 14845000
. : milestone, 14845000,
iast (18.446 s) : 18446000, 18446000
. : milestone, 18446000,
iast_GLOBAL (18.098 s) : 18098000, 18098000
. : milestone, 18098000,
profiling (15.189 s) : 15189000, 15189000
. : milestone, 15189000,
tracing (14.936 s) : 14936000, 14936000
. : milestone, 14936000,
section candidate
no_agent (14.857 s) : 14857000, 14857000
. : milestone, 14857000,
appsec (14.944 s) : 14944000, 14944000
. : milestone, 14944000,
iast (18.423 s) : 18423000, 18423000
. : milestone, 18423000,
iast_GLOBAL (17.717 s) : 17717000, 17717000
. : milestone, 17717000,
profiling (14.834 s) : 14834000, 14834000
. : milestone, 14834000,
tracing (14.725 s) : 14725000, 14725000
. : milestone, 14725000,
|
|
|
||
| /** Called on mount: swaps the virtual thread's context into the carrier thread. */ | ||
| public void onMount() { | ||
| this.previousContext = this.context.swap(); |
There was a problem hiding this comment.
Nice, that's the kind of API that I was imagining
|
/merge |
|
View all feedbacks in Devflow UI.
The expected merge time in
|
What Does This Do
This PR addresses the following issues with
VirtualThreadinstrumentation:VirtualThreadas aRunnablewhen virtual thread instrumentation is enabledafterDone()andafterDone(boolean)leading to duplicate clearing workState/ConcurrentStateAPI instead of using the new Context swap API. This lead to ouf of order scope closing in addition to increase pressure on health metrics.Motivation
I did not check at bytecode level the changes from the original PRs and that was wrong. That introduces regression and keep pushing in the wrong direction. This is a basically a redo of the instrumentation using context swap and continuation.
Additional Notes
This PR also mirrors the context testing capability from the JUnit instrumentation tests.
Contributor Checklist
type:and (comp:orinst:) labels in addition to any other useful labelsclose,fix, or any linking keywords when referencing an issueUse
solvesinstead, and assign the PR milestone to the issueJira ticket: [PROJ-IDENT]
Note: Once your PR is ready to merge, add it to the merge queue by commenting
/merge./merge -ccancels the queue request./merge -f --reason "reason"skips all merge queue checks; please use this judiciously, as some checks do not run at the PR-level. For more information, see this doc.